← Course index · R314 System & Network
MMIBUT Métiers du Multimédia et de l'Internet · IUT de Vélizy

Lab · Linux Rocky / CentOS

Module MM1R13 Hosting — basic commands and utilities: file tree, shell, files, permissions and wildcards.

TPShellVirtualBoxSystem

01Objectives & setup

Goal

Learn to use a workstation in a Linux environment.

Software

VirtualBox.

Assessment

A detailed report written with a word processor.

Manipulation

User account

User: toto · Password: toto01

Administrator (root)

User: root · Password: linux2002

02Introduction & directory structure

We use Linux to learn system administration. A key advantage: most configuration files are text files, editable with simple tools such as gedit, nano or emacs. Most Unix-derived systems share a similar directory hierarchy:

DirectorySub-directoriesContent
/bin/usr/bin
/usr/local/bin
Basic commands; additional commands added by the admin.
/sbin/usr/sbinSystem administration commands.
/bootLinux kernel files.
/devSpecial device files (peripherals).
/etc/etc/rc.d
/etc/init.d
System configuration files; service startup scripts.
/homeUsers' personal directories.
/lib/usr/libLibraries (shared code) used by programs.
/mnt/mnt/cdrom
/mnt/usb
Mount points for removable media (CD, USB).
/rootHome directory of the administrator.
/tmpTemporary files.
/usr/usr/include
/usr/share/man
Main system directory: header files, Linux manuals.
/var/var/log
/var/spool
Variable data: system logs, mailboxes.

03Part 1 — Generalities and organisation

Explore the Linux file tree:

  1. In which directory is your $HOME directory located (where $HOME is your login)?
  2. Which files and directories does your $HOME contain? (Don't forget "hidden" files, starting with a .)
  3. Go back to your $HOME. Using the graphical interface (right-click menu), create then delete a folder and a file in $HOME.
  4. Task: create the following tree, starting from your $HOME:
~ ├── Initiation_Systeme ├── Bureautique ├── Linux │ └── TP1 └── Programmation

04Part 2 — The command interpreter (shell)

Command-line interpreters (shells) such as bash let you work faster than with a graphical interface.

  1. Launch a shell: open the terminal. A line ending with $ appears: this is the prompt.
  2. Explore these commands:
    • Find out what whoami and ps do. Use man [command] to read the documentation (press q to quit).
    • Look up pwd, whoami and ps.
  3. Aliases (shortcuts):
    • What does ls do? Check with the file manager.
    • Try ls -a, ls -al, then ls -al --color=auto. Compare the results.
    • Use man alias to see how to create one.
    • Task: create an alias named llc that behaves like ls -la --color=auto, and check that it works.
    • Type exit to close the shell. Open a new one and try llc again: it has disappeared (it was temporary). To make it permanent, add it to the .bashrc file.

05Part 3 — Moving in a directory tree

Enter a folder

cd [folder_name]

Go up one level

cd ..

  1. Create a directory TP2 inside the Linux directory.
  2. Open a terminal. Check you are in $HOME with pwd, and check its content with ls.
  3. Enter the Programmation directory. Check with pwd.
  4. Leave Programmation. Check with pwd.
  5. Go to your TP2 directory (Linux → TP2). Check with pwd.

06Part 4 — File creation & manipulation

CommandFunctionSyntaxExample
touchCreate an empty filetouch [PATH/]FILEtouch /mmi/test
nanoEdit a text filenano [PATH/]FILEnano /mmi/test
lessView contentless [PATH/]FILEless /mmi/test
rmRemove a filerm [PATH/]FILErm /mmi/test
mvMove or renamemv SOURCE DESTmv test test2
cpCopy a filecp SOURCE DESTcp test test2
  1. Go to the TP2 sub-directory, then create an empty file named bonjour with touch (check the man pages if needed).
  2. Check that the file is empty with cat.
  3. Write "Hello World" into bonjour: type cat > bonjour, then the sentence. Finish with Ctrl + D.
  4. Display the content of bonjour with cat.
  5. Add "How do you do?" at the end of bonjour: type cat >> bonjour, then your text. Finish with Ctrl + D.
  6. Check the result by displaying bonjour again.
  7. With cp, copy bonjour into a new file named salut (still in TP2). Check that both files are identical with diff.
  8. Type cat > salut, then a new sentence, and finish with Ctrl + D. Display salut. What happened? What is the difference between > and >>?
Redirection symbols: > and >> are called redirection symbols.

07Part 5 — Access rights (permissions)

In Linux, every file or folder has rights for three types of users: the owner (user), the group and others. The rights are read (r), write (w) and execute (x).

-rw-r--r-- type · owner · group · others │ └┬┘└┬┘└┬┘ │ │ │ └── others │ │ └───── group │ └──────── owner (user) └─────────── "-" file, "d" directory
  1. Make sure you are in your TP2 directory.
  2. Display the details of the files with ls -l (or your alias llc) and look at the first column (e.g. -rw-r--r--).
  3. Make bonjour confidential by removing read rights for the group and others: chmod go-r bonjour (g group, o others, - remove, r read).
  4. Check the result with ls -l. You should see something like -rw-------.
  5. Now let everyone write to the file (dangerous in real life!): chmod a+w bonjour (a for all). Check again with ls -l.
  6. Restore the original rights (read/write for you, read-only for others) with octal notation: chmod 644 bonjour.

4 = read (r)

6 = 4 + 2 → rw-

2 = write (w)

7 = 4 + 2 + 1 → rwx

1 = execute (x)

644 → rw-r--r--

08Part 6 — Search, wildcards and cleanup

  1. Create 3 more empty files: touch note1.txt note2.txt image.jpg
  2. Use the wildcard * to list all files starting with "note": ls note*
  3. List all files with the ".txt" extension: ls *.txt
  4. Delete image.jpg: rm image.jpg. The system may ask for confirmation: type "y".
  5. Delete all files starting with "note" in one command: rm note*
  6. Go up one level to leave TP2: cd ..
  7. Try to delete the folder with rm TP2. What happens? By default, rm does not delete directories.
  8. To delete a directory and all its content (bonjour and salut), use the recursive option: rm -r TP2
  9. Check that the folder has gone with ls.